import Vue from 'vue'
import Router from 'vue-router'
import Layout from '@/views/layout'
const routerPush = Router.prototype.push
Router.prototype.push = function push(location) {
  return routerPush.call(this, location).catch(error => error)
}
Vue.use(Router)

const _import = file => () => import('@/views/' + file + '.vue')

const single = [
  {
    path: '/login',
    component: _import('login/index'),
    meta: {
      requireAuth: false,
      hidden: true
    }
  },
  {
    path: '*',
    component: _import('error-page/index'),
    meta: {
      requireAuth: false,
      hidden: true
    }
  }
]

export const routes = [
  {
    path: '/',
    component: Layout,
    meta: {
      title: '首页',
      only: true, // 只显示父级
      icon: 'icon-iconfontzhizuobiaozhun023101'
    },
    children: [
      {
        path: '',
        component: _import('dashboard/index'),
        meta: { hidden: true, title: '首页' }
      }
    ]
  },
  {
    path: '/domain',
    component: Layout,
    meta: { title: '域名模块', icon: 'icon-redianshijian' },
    children: [
      {
        path: '/domain/index',
        component: _import('domain/domain/index'),
        meta: { title: '域名管理', icon: 'icon-xingxing' },
        children: [
          {
            path: 'domain',
            component: _import('domain/domain/domain'),
            meta: { title: '域名' }
          }
        ]
      },
      {
        path: '/subdomain/index',
        component: _import('domain/subdomain/index'),
        meta: { title: '子域名模块', icon: 'icon-xingxing' },
        children: [
          {
            path: 'subdomain',
            component: _import('domain/domain/subdomain'),
            meta: { title: '子域名' }
          }
        ]
      }
    ]
  },
  {
    path: '/website',
    component: Layout,
    meta: { title: '网站模块', icon: 'icon-weixin' },
    children: [
      {
        path: 'index',
        component: _import('domain/website/index'),
        meta: { title: '网站' }
      },
      {
        path: 'website',
        component: _import('domain/website/website'),
        meta: { title: '网站管理' }
      }
    ]
  }
]

export const asyncRoutes = [
  {
    path: '/async',
    component: Layout,
    meta: {
      title: '异步模块',
      role: ['admin'],
      only: true,
      icon: 'icon-zhuanhuan'
    },
    children: [
      {
        path: '',
        component: _import('async/index'),
        meta: {
          title: '异步',
          role: ['admin'],
          hidden: true
        }
      }
    ]
  },
  {
    path: '/promotion',
    component: Layout,
    meta: {
      title: '推广模块',
      role: ['admin', 'promotion'],
      only: true,
      icon: 'icon-pengyouquan'
    },
    children: [
      {
        path: '',
        component: _import('promotion/index'),
        meta: {
          title: '推广',
          role: ['admin', 'promotion'],
          hidden: true
        }
      }
    ]
  }
]

export default new Router({
  // scrollBehavior: {
  //   y: 0
  // },
  routes: [...routes, ...single]
  // mode: 'history'
})
